from sqlmodel import SQLModel, Field
from typing import Optional
from datetime import datetime


class UserRole(str):
    ADMIN = "admin"
    USER = "user"
    GUEST = "guest"


class User(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    username: str = Field(..., unique=True, description="用户名")
    email: str = Field(..., unique=True, description="邮箱")
    full_name: Optional[str] = Field(default=None, description="全名")
    hashed_password: str = Field(..., description="哈希后的密码")
    role: str = Field(default=UserRole.USER, description="用户角色")
    is_active: bool = Field(default=True, description="是否激活")
    is_superuser: bool = Field(default=False, description="是否为超级用户")
    created_at: datetime = Field(default_factory=datetime.now, description="创建时间")
    last_login: Optional[datetime] = Field(default=None, description="最后登录时间")